


/*One of the Functions used to get field value of frame */
FUNCTION GetTopParent RETURNS HANDLE (INPUT piParentHandle AS HANDLE):

DEFINE VARIABLE poTopParent AS HANDLE NO-UNDO.

IF VALID-HANDLE(piParentHandle) THEN
DO:
  IF piParentHandle:TYPE = "WINDOW" THEN
  DO:
    ASSIGN poTopParent = piParentHandle.
    RETURN poTopParent.
  END.
  ELSE DO:
    ASSIGN piParentHandle = piParentHandle:PARENT.
    poTopParent = GetTopParent (piParentHandle).
    IF VALID-HANDLE(poTopParent) THEN
      RETURN poTopParent.
    ELSE
      RETURN ?.
  END. /* ELSE DO */
END. /* IF VALID-HANDLE */
END FUNCTION.
  
  
  
  
  
  
PROCEDURE GetFrame:
DEFINE INPUT PARAMETER piHandle    AS HANDLE NO-UNDO.
DEFINE INPUT PARAMETER piFrameName AS CHAR   NO-UNDO.
DEFINE OUTPUT PARAMETER poHandle   AS HANDLE NO-UNDO.

DEFINE VARIABLE hChild AS HANDLE NO-UNDO.

IF VALID-HANDLE(piHandle) THEN
DO:
  ASSIGN hChild = piHandle:FIRST-CHILD.
  REPEAT WHILE(VALID-HANDLE(hChild)):
    IF hChild:TYPE = "FRAME" AND hChild:NAME = piFrameName THEN
    DO:
      ASSIGN poHandle = hChild.
      LEAVE.
    END.
    ELSE hChild = hChild:NEXT-SIBLING.
  END.
END.
RETURN "".
END PROCEDURE.


PROCEDURE GetFieldValue:
DEFINE INPUT PARAMETER piFieldName   AS CHAR NO-UNDO.
DEFINE INPUT PARAMETER piFrameName   AS CHAR NO-UNDO.
DEFINE OUTPUT PARAMETER poFieldValue AS CHAR NO-UNDO.

 DEFINE VARIABLE hparent     AS HANDLE     NO-UNDO.
 DEFINE VARIABLE hfldgrp     AS HANDLE     NO-UNDO.
 DEFINE VARIABLE hfield      AS HANDLE     NO-UNDO.


ASSIGN hparent = GetTopParent (SELF).
IF VALID-HANDLE(hparent) THEN
DO:
  RUN GetFrame IN THIS-PROCEDURE
    (INPUT hparent, INPUT piFrameName, OUTPUT hfield).
  IF VALID-HANDLE(hfield) THEN
  DO:
    ASSIGN hfield = hfield:FIRST-CHILD.
    /*
    message hfield:TYPE view-as alert-box.
    */
    IF hfield:TYPE = "FIELD-GROUP" THEN
    DO:
      ASSIGN hfldgrp = hfield.
      fldgrp:
      REPEAT WHILE(VALID-HANDLE(hfldgrp)):
        ASSIGN hfield = hfldgrp:FIRST-CHILD.
        fld:
        REPEAT WHILE(VALID-HANDLE(hfield)):
                IF hfield:NAME = piFieldName THEN
                DO:
                  ASSIGN poFieldValue = hfield:SCREEN-VALUE.
                  LEAVE fldgrp.
            END.  /* END IF hfield:NAME = "pod_reason" THEN */
            ELSE hfield = hfield:NEXT-SIBLING.
        END. /* END REPEAT WHILE(VALID-HANDLE(hfldgrp)): */
        ASSIGN hfldgrp = hfldgrp:NEXT-SIBLING.
      END.  /* END REPEAT WHILE(VALID-HANDLE(hfldgrp)):*/
    END.  /* END IF hfield:TYPE = "FIELD-GROUP" THEN */
    ELSE
    DO:
      REPEAT WHILE(VALID-HANDLE(hfield)):
        IF hfield:NAME = piFieldName THEN
        DO:
          ASSIGN poFieldValue = hfield:SCREEN-VALUE.
          LEAVE.
        END.   /* END IF hfield:NAME = "pod_reason" THEN */
        ELSE hfield = hfield:NEXT-SIBLING.
      END.  /* END REPEAT WHILE(VALID-HANDLE(hfield)): */
    END.   /* END ELSE IF hfield:TYPE = "FIELD-GROUP" THEN */
  END.  /* END IF VALID-HANDLE(hfield) THEN */
  ELSE RETURN "Not a valid frame".
END.  /* END IF VALID-HANDLE(hparent) THEN  */
ELSE RETURN "Not a valid handle".
RETURN "".
END PROCEDURE.

PROCEDURE SetFieldValue:
DEFINE INPUT PARAMETER piFieldName    AS CHAR NO-UNDO.
DEFINE INPUT PARAMETER piFrameName    AS CHAR NO-UNDO.
DEFINE INPUT PARAMETER piFieldValue   AS CHAR NO-UNDO.
DEFINE OUTPUT PARAMETER poResult      AS LOG  NO-UNDO.

DEFINE VARIABLE hparent     AS HANDLE     NO-UNDO.
DEFINE VARIABLE hfldgrp     AS HANDLE     NO-UNDO.
DEFINE VARIABLE hfield      AS HANDLE     NO-UNDO.

ASSIGN hparent  = GetTopParent (SELF)
       poResult = NO.
IF VALID-HANDLE(hparent) THEN
DO:
  RUN GetFrame IN THIS-PROCEDURE
    (INPUT hparent, INPUT piFrameName, OUTPUT hfield).

  IF VALID-HANDLE(hfield) THEN
  DO:
    ASSIGN hfield = hfield:FIRST-CHILD.
    IF hfield:TYPE = "FIELD-GROUP" THEN
    DO:
      ASSIGN hfldgrp = hfield.
      fldgrp:
      REPEAT WHILE(VALID-HANDLE(hfldgrp)):
        ASSIGN hfield = hfldgrp:FIRST-CHILD.
        fld:
        REPEAT WHILE(VALID-HANDLE(hfield)):
                IF hfield:NAME = piFieldName THEN
                DO:
                  ASSIGN hfield:SCREEN-VALUE = piFieldValue
                         hfield:READ-ONLY = True 
                         hfield:MODIFIED =false
                         poResult = YES.
                  LEAVE fldgrp.
            END.  /* END IF hfield:NAME = "pod_reason" THEN */
            ELSE hfield = hfield:NEXT-SIBLING.
        END. /* END REPEAT WHILE(VALID-HANDLE(hfldgrp)): */
        ASSIGN hfldgrp = hfldgrp:NEXT-SIBLING.
      END.  /* END REPEAT WHILE(VALID-HANDLE(hfldgrp)):*/
    END.  /* END IF hfield:TYPE = "FIELD-GROUP" THEN */
    ELSE
    DO:
      REPEAT WHILE(VALID-HANDLE(hfield)):
        IF hfield:NAME = piFieldName THEN
        DO:
          ASSIGN hfield:SCREEN-VALUE = piFieldValue
          hfield:READ-ONLY = True 
           hfield:MODIFIED =false
                 poResult = YES.
          LEAVE.
        END.   /* END IF hfield:NAME = "pod_reason" THEN */
        ELSE hfield = hfield:NEXT-SIBLING.
      END.  /* END REPEAT WHILE(VALID-HANDLE(hfield)): */
    END.   /* END ELSE IF hfield:TYPE = "FIELD-GROUP" THEN */
  END.  /* END IF VALID-HANDLE(hfield) THEN */
  ELSE RETURN "Not a valid frame".
END.  /* END IF VALID-HANDLE(hparent) THEN  */
ELSE RETURN "Not a valid handle".
RETURN "".
END PROCEDURE.
